// useRouter 只能用在组件上


import router from "./router";
import { useToken } from "./stores/token";

const whiteList: string[] = ["/login", "/404"]
// 前置守卫
router.beforeEach((to, from, next) => {
  const store = useToken()
  // 有token情况下
  if (store.getToken()) {
    if (to.path === '/login') {
      next("/")
    } else {
      next()
    }
  }
  else {
    // 无token情况下
    if (whiteList.includes(to.path)) {
      next()
    } else {
      next("/login")
    }

  }
})

// 后置守卫
router.afterEach(() => {

})
